package com.cefa.edu.service;

import com.cefa.edu.dao.CourseMapper;
import com.cefa.edu.pojo.Course;
import com.google.common.base.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by cc664 on 2018/8/15.
 * @aa courseService
 */
@Service
public class CourseService {
    @Autowired
    CourseMapper courseMapper;
    /**
     * @aa 添加科目数据
     * @param schoolId
     * @param gradeId
     * @param courseName
     * @return
     */
    public int saveCourse(Integer schoolId, Integer gradeId, String courseName,String recordNames) {

        //添加科目数据
        Map<String,Object> paramsMap=new HashMap<String,Object>();
        paramsMap.put("schoolId",schoolId);
        paramsMap.put("gradeId",gradeId);
        paramsMap.put("courseName",courseName);
        paramsMap.put("recordNames",recordNames);
        if(Strings.isNullOrEmpty(recordNames)){
            paramsMap.put("recordNames","");
        }
        int res=  courseMapper.saveCourse(paramsMap);

        return res;
    }

    /**
     * @aa 根据班级id 删除班级
     * @aa add by chaijian 2018-08-15
     * @param courseId
     * @return
     */
    @Transactional
    public void deleteClass(Integer courseId) {
        courseMapper.deleteCourse(courseId);
    }

    /**
     * @aa 根据科目id 获取对应的班级数据
     * @aa add by chaijian 2018-08-15
     * @return
     */
    public Map<String,Object> getCourseById(Integer courseId) {
     return   courseMapper.getCourseById2(courseId);
    }

    public int updateCourse(Course course ) {
        return   courseMapper.updateCourse(course);
    }

    public int isExistedOfTheGradeCourse(Integer schoolId, Integer gradeId, String courseName) {
        return courseMapper.isExistedOfTheGradeCourse(schoolId,gradeId,courseName);
    }
}
